package com.njwb.day09.exec;



import org.apache.log4j.Logger;

import java.util.InputMismatchException;
import java.util.Scanner;

public class ExceDemo01 {
    //获取日志管理器
    public static Logger logger = Logger.getLogger("com.njwb.exec.ExecDemo01");
    public static void main(String[] args) {
        //try...catch..finally
        try {
            choiceCourse();
        } catch (CourseException e) {
            logger.debug(e.getMessage());
            logger.info(e.getMessage());
            logger.warn(e.getMessage());
            logger.error(e.getMessage());
            logger.fatal(e.getMessage());

        }catch(InputMismatchException e ) {
            logger.debug("输入错误，必须是数字");
            logger.info("输入错误，必须是数字");
            logger.warn("输入错误，必须是数字");
            logger.error("输入错误，必须是数字");
            logger.fatal("输入错误，必须是数字");
        }catch(Exception e) {
            logger.debug("发生了错误，请查看错误原因:"+e.getMessage());

        }finally {
            System.out.println("欢迎提出建议");
        }
    }

    //声明抛出异常
    public static void choiceCourse() throws CourseException{
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入课程代号（1-3之间的数字）:");
        int courseNo = scanner.nextInt() ;
        switch (courseNo) {
            case 1:
                System.out.println("c#编程");
                break;
            case 2:
                System.out.println("python编程");
                break;
            case 3:
                System.out.println("java编程");
                break;
            default:
                //自行抛出一个异常对象，（自定义异常类）
                throw new CourseException("课程编号不正确，必须在1-3之间");
        }
    }
}
